import Cookies from "js-cookie"

const TokenKey = "token"

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

/**
 *批量谷歌地图经纬度转换成百度经纬度
 * @param { Array } pArray 点集合
 */
export function multiGoogleToBaidu(pArray, BMap) {
  const xpi = (3.14159265358979324 * 3000.0) / 180.0
  const bpArray = []
  for (var i = 0; i < pArray.length; i++) {
    var ggPoint = pArray[i]
    var x = ggPoint.lng
    var y = ggPoint.lat
    var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * xpi)
    var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * xpi)
    var bdx = Number(Number(z * Math.cos(theta) + 0.0065).toFixed(6))
    var bdy = Number(Number(z * Math.sin(theta) + 0.006).toFixed(6))
    var p = new BMap.Point(bdx, bdy)
    bpArray.push(p)
  }
  return bpArray
}

/**
 *批量谷歌地图经纬度转换成百度经纬度
 * @param 点
 */
export function pointToBaidu(point, BMap) {
  const xpi = (3.14159265358979324 * 3000.0) / 180.0
  const x = point.lng
  const y = point.lat
  const z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * xpi)
  const theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * xpi)
  const bdx = Number(Number(z * Math.cos(theta) + 0.0065).toFixed(6))
  const bdy = Number(Number(z * Math.sin(theta) + 0.006).toFixed(6))
  const p = new BMap.Point(bdx, bdy)
  return p
}
